<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if !IE]><!-->
<html lang="zh">
<!--<![endif]-->
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
%>

<head>
    <meta charset="utf-8" />
    <title>保险代理后台管理系统</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
    <!-- ================== BEGIN BASE CSS STYLE ================== -->
    <jsp:include page="../common/header.jsp"></jsp:include>
    <%@include file="../common/taglib.jsp"%>
    <!-- ================== END BASE CSS STYLE ================== -->

    <!-- ================== 单独作用于本页表格td ================== -->
    <style>
        .baseCheckJstShow {
            margin-bottom: 0;
        }
        .checkJstShow1 {
            margin-left:0px;
        }
        .checkJstShow2 {
            margin-left:20px;
        }
        .checkJstShow3 {
            margin-left:40px;
        }
        .checkJstShow4 {
            margin-left:60px;
        }
        ol,ul{
            list-style: none;
        }
        label.control-label.col-md-2.col-sm-4{
            width: 90px;
        }
        .col-md-6.col-sm-6 .form-control {
            width: 280px;
        }
    </style>
    <!-- ================== 单独作用于本页表格td ================== -->

</head>
<body>
<!-- begin #page-loader -->
<div id="page-loader" class="fade in"><span class="spinner"></span></div>
<!-- end #page-loader -->

<!-- begin #page-container -->
<div id="page-container" class="fade page-sidebar-fixed page-header-fixed">
    <jsp:include page="../common/top.jsp"/>

    <!-- begin #sidebar -->
    <jsp:include page="../common/sitebar.jsp"/>
    <div class="sidebar-bg"></div>
    <!-- end #sidebar -->

    <!-- begin #content -->
    <div id="content" class="content">
        <div class="row">

            <div class="col-md-12">
                <ul id ="insurerTabs" class="nav nav-tabs">
                    <li class="active"><a href="#default-tab-1" data-toggle="tab" onclick=" cleacleanTabs();">角色列表</a></li>
                    <shiro:hasPermission name="sysMag:role:new">
                    <li class=""><a href="#default-tab-2" data-toggle="tab" onclick=" cleacleanTabs();">新建角色</a></li>
                    </shiro:hasPermission>
                </ul>

                <div class="tab-content">
                    <div class="tab-pane fade active in" id="default-tab-1">
                        <div>
                            <div class="form-inline">
                                <div class="form-group m-r-20">
                                    <label>角色名称：</label>
                                    <input type="text" class="form-control" id="gadname" placeholder="角色名称" />
                                </div>
                                <div class="form-group m-r-10">
                                    <label>状态：</label>
                                    <select class="form-control" type="text" id="status" name="status"/>
                                        <option value="">请选择</option>
                                        <option value="0">使用中</option>
                                        <option value="1">已禁用</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-primary" onclick="search()" >查询</button>
                            </div>
                           <%-- <input type="text" class="form-control" id="gadname" placeholder="查询条件：角色名称\描述" style="position: relative;width: 200px;top: 22px;">
                            <button type="button" class="btn btn-primary" style="position: relative;top:-13px;left:223px;">查询</button>--%>

                            <table id="gadtable" class="table table-striped table-bordered"  style= "word-break:break-all;word-wrap:break-word">
                                <thead>
                                <tr>
                                    <th width="20%">角色名称</th>
                                    <th width="20%">角色部门</th>
                                    <th width="20%">数据范围</th>
                                    <th width="10%">状态</th>
                                    <th width="10%">创建时间</th>
                                    <th width="10%">修改时间</th>
                                    <th width="10%">操作</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                    <shiro:hasPermission name="sysMag:role:new">
                    <div class="tab-pane fade" id="default-tab-2">
                        <div class="panel panel-inverse" data-sortable-id="form-validation-1">
                            <div class="panel-body panel-form">
                                <form id="addRoleForm" role="form" method="post" class="form-horizontal form-bordered" data-parsley-validate="true" onsubmit="return check(this);">
                                    <div class="form-group">
                                        <label class="control-label col-md-2 col-sm-4">部门：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <select class="form-control" type="text" id="departmentId" name="departmentId" onchange="getDataType('XXXX');" data-parsley-required="true" data-parsley-required-message="部门不能为空" />
                                            <option value="">请选择</option>
                                            <c:forEach items="${departmentList}" var="dl">
                                                <option value="${dl.tid}">${dl.officeName}</option>
                                            </c:forEach>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-2 col-sm-4">角色名称：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" id="add_Name" name="name" data-parsley-required="true" data-parsley-required-message="角色名称不能为空"
                                                   data-parsley-person-name="true" data-parsley-person-name-message="角色名称只能为英文和汉字"
                                                   data-parsley-maxlength="30"  data-parsley-maxlength-message="角色名称最长为30位"/>
                                            <span id="spanMessage"></span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2 col-sm-4">数据范围：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input type="hidden" class="form-control" id="roleLevel" name="roleLevel">
                                            <select class="form-control" id="roleTypeId" name="roleTypeId" onchange="setLevel();" data-parsley-required="true" data-parsley-required-message="数据范围不能为空">
                                                <option value="">请选择</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-2 col-sm-4">角色授权：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <ul>
                                                <c:forEach items="${rootMenu}" var="rootMenu">
                                                <li>
                                                    <label>
                                                        <input type="checkbox" onclick="oneOnclick(this)" name="idList"  value="${rootMenu.tid}"/>
                                                            ${rootMenu.description}
                                                    </label>
                                                    <ul>
                                                        <c:forEach items="${childMenu}" var="childMenu">
                                                            <c:if test="${rootMenu.tid == childMenu.parentId}">
                                                                <li>
                                                                    <label>
                                                                        <input type="checkbox" onclick="oneOnclick(this)" name="idList"  value="${childMenu.tid}"/>
                                                                            ${childMenu.description}
                                                                    </label>
                                                                    <ul>
                                                                        <c:forEach items="${childPage}" var="childPage">
                                                                            <c:if test="${childMenu.tid == childPage.parentId}">
                                                                                <li>
                                                                                    <label>
                                                                                        <input type="checkbox" onclick="oneOnclick(this)" name="idList"  value="${childPage.tid}"/>
                                                                                            ${childPage.description}
                                                                                    </label>
                                                                                    <ul>
                                                                                    <c:forEach items="${childButton}" var="childButton">
                                                                                        <c:if test="${childPage.tid == childButton.parentId}">
                                                                                            <li>
                                                                                                <label>
                                                                                                    <input type="checkbox" name="idList"  value="${childButton.tid}"/>
                                                                                                        ${childButton.description}
                                                                                                </label>
                                                                                            </li>
                                                                                        </c:if>
                                                                                    </c:forEach>
                                                                                    </ul>
                                                                                </li>
                                                                            </c:if>
                                                                        </c:forEach>
                                                                    </ul>
                                                                </li>
                                                            </c:if>
                                                        </c:forEach>
                                                    </ul>
                                                </li>
                                                </c:forEach>
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2 col-sm-4"></label>
                                        <div class="col-md-6 col-sm-6">
                                            <button type="submit" class="btn btn-primary">提  交</button>
                                            <button type="button" onClick="goBack()" class="btn btn-default">取  消</button>
                                        </div>

                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    </shiro:hasPermission>
                    <shiro:hasPermission name="sysMag:role:list:edit">
                    <div class="tab-pane fade" id="default-tab-3">
                        <div class="panel panel-inverse" data-sortable-id="form-validation-1">
                            <div class="panel-body panel-form">
                                <form id="editRoleForm" role="form" method="post" class="form-horizontal form-bordered" data-parsley-validate="true" onsubmit="return check(this);">
                                    <input type="hidden" class="form-control" id="tid" name="tid" value="">
                                    <div class="form-group">
                                        <label class="control-label col-md-2 col-sm-4">部门:</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input type="hidden" class="form-control" id="departmentEId" name="departmentEId">
                                            <input class="form-control" type="text" name="departmentName" id="departmentName" disabled/>
                                            <%--<select class="form-control" type="text" id="departmentId" name="departmentId" disabled onchange="getEDataType('XXXX');" data-parsley-required="true" data-parsley-required-message="部门不能为空" />
                                            <option value="">请选择</option>
                                            <c:forEach items="${departmentList}" var="dl">
                                                <option value="${dl.tid}">${dl.officeName}</option>
                                            </c:forEach>
                                            </select>--%>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2 col-sm-4">角色名称:</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" name="name" id="name" disabled data-parsley-required="true" data-parsley-required-message="角色名称不能为空"
                                                   data-parsley-person-name="true" data-parsley-person-name-message="角色名称只能为英文和汉字"
                                                   data-parsley-maxlength="30"  data-parsley-maxlength-message="角色名称最长为30位"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2 col-sm-4">数据范围:</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input type="hidden" class="form-control" id="roleELevel" name="roleLevel" value="${role.roleLevel}">
                                            <select class="form-control" id="roleETypeId" name="roleTypeId" onchange="setELevel();" data-parsley-required="true" data-parsley-required-message="数据范围不能为空">
                                                <option value="">请选择</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-2 col-sm-4">角色授权</label>
                                        <div class="col-md-6 col-sm-6">
                                            <ul id="authIdsShow">
                                                <c:forEach items="${rootMenu}" var="rootMenu">
                                                    <li>
                                                        <label>
                                                            <c:set var="rmIds">,${rootMenu.tid},</c:set>
                                                            <input type="checkbox" onclick="oneOnclick(this)" name="idList"  value="${rootMenu.tid}" <c:if test="${ role.authIds.indexOf(rmIds)>-1 }"> checked="checked"</c:if> />
                                                                ${rootMenu.description}
                                                        </label>
                                                        <ul>
                                                            <c:forEach items="${childMenu}" var="childMenu">
                                                                <c:if test="${rootMenu.tid == childMenu.parentId}">
                                                                    <li>
                                                                        <label>
                                                                            <input type="checkbox" onclick="oneOnclick(this)" name="idList"  value="${childMenu.tid}"/>
                                                                                ${childMenu.description}
                                                                        </label>
                                                                        <ul>
                                                                            <c:forEach items="${childPage}" var="childPage">
                                                                                <c:if test="${childMenu.tid == childPage.parentId}">
                                                                                    <li>
                                                                                        <label>
                                                                                            <input type="checkbox" onclick="oneOnclick(this)" name="idList"  value="${childPage.tid}"/>
                                                                                                ${childPage.description}
                                                                                        </label>
                                                                                        <ul>
                                                                                            <c:forEach items="${childButton}" var="childButton">
                                                                                                <c:if test="${childPage.tid == childButton.parentId}">
                                                                                                    <li>
                                                                                                        <label>
                                                                                                            <input type="checkbox" name="idList"  value="${childButton.tid}"/>
                                                                                                                ${childButton.description}
                                                                                                        </label>
                                                                                                    </li>
                                                                                                </c:if>
                                                                                            </c:forEach>
                                                                                        </ul>
                                                                                    </li>
                                                                                </c:if>
                                                                            </c:forEach>
                                                                        </ul>
                                                                    </li>
                                                                </c:if>
                                                            </c:forEach>
                                                        </ul>
                                                    </li>
                                                </c:forEach>
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2 col-sm-4"></label>
                                        <div class="col-md-6 col-sm-6">
                                            <button type="submit" class="btn btn-primary">提  交</button>
                                            <button type="button" onClick="goBack()" class="btn btn-default">取  消</button>
                                        </div>

                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    </shiro:hasPermission>
                </div>
            </div>
        </div>
        <!-- end row -->
        <div class="modal fade" id="modal-subInfo">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">温馨提示</h4>
                    </div>
                    <div id="showSubInfo" class="modal-body">
                        当前填写内容未提交，确认取消？
                    </div>
                    <div class="modal-footer">
                        <a href="javascript:;" id="subButtonYes" class="btn btn-primary">确定</a>
                        <a href="javascript:;" id="subButtonNo" class="btn btn-default" data-dismiss="modal">取消</a>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <!-- end #content -->

</div>
<!-- end page container -->
<jsp:include page="../common/footer.jsp"/>

<!-- ================== END PAGE LEVEL JS ================== -->

<script>
    var roleIds = "${roleIds}";
    $(document).ready(function() {
        App.init();
        TableManageFixedHeader.init();
        Dashboard.init();
        getDataType();
        <shiro:hasPermission name="sysMag:role:new">
        $('#addRoleForm').parsley().on('form:submit', function() {
            submitAddInfo();return false;
        });
        </shiro:hasPermission>
        <shiro:hasPermission name="sysMag:role:list:edit">
        $('#editRoleForm').parsley().on('form:submit', function() {
            submitEditInfo();return false;
        });
        </shiro:hasPermission>
    });
    window.ParsleyValidator.addValidator('personName', function(value) {
        if(value!= ""){
            return /^[\u0391-\uFFE5A-Za-z]+$/.test(value);
        }
        return true;
    },32);

    //去往编辑页面
    function toedit(id){
        $("#insurerTabs").find("li").each(function(){
            $(this).removeClass("active");
        });
        $("#insurerTabs").append('<li class="active"><a href="#default-tab-3" data-toggle="tab">编辑角色</a></li>');
        $("#default-tab-1").removeClass("active in");
        $("#default-tab-3").addClass("active in");
        jQuery.ajax({
            type: "GET",
            url: "<%=path%>/sysrole/toedit/"+id,
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    $("#tid").val(data.result.tid);
                    $("#departmentEId").val(data.result.departmentId);
                    $("#departmentName").val(data.result.departmentName);
                    $("#name").val(data.result.name);
                    $("#roleELevel").val(data.result.roleLevel);
                    getEDataType(data.result.roleTypeId);
                    var authIds = data.result.authIds;
                    $("#authIdsShow").find("input[name='idList']").each(function () {
                        $(this).attr("checked",false);
                        var tid = ","+$(this).val()+",";
                        if(authIds.indexOf(tid)>-1){
                            $(this).attr("checked",true);
                        }
                    });
                }
            }
        });
    }

    //去往新增页面
    function toadd(){
        window.location.href="<%=path%>/sysrole/toadd";
    }

    //删除
    function upRoleFlag(id,flag) {
        var info = "确认禁用该用户？";
        if(0==flag){
            info = "确认解禁该用户？";
        }
        Ewin.confirm({message: info}).on(function (e) {
            if (!e) {
                return;
            }
            var param = {};
            param.flag = flag;
            param.tid = id;
            jQuery.ajax({
                type: "GET",
                url: "<%=path%>/sysrole/uprole/",
                dataType: "json",
                data:param,
                success: function (data) {
                    if (data.success == true) {
                        $("#showSubInfo").html(" 操作成功!");
                        $("#subButtonYes").attr("onclick","toRefresh();");
                        $("#modal-subInfo").modal('show');
                        /*$("#gadtable").hide();
                        location.reload();*/
                    } else {
                        $("#showSubInfo").html(" 操作失败!");
                        $("#subButtonYes").attr("onclick","closeModal();");
                        $("#modal-subInfo").modal('show');
                    }

                }
            });
        });
    }



    var table;
    $(document).ready(function() {
        table = $("#gadtable").DataTable( {
            "pagingType": "simple_numbers",//设置分页控件的模式
            searching: false,//屏蔽datatales的查询框
            aLengthMenu:[15],//设置一页展示10条记录
            "ordering": false,
            "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
            "oLanguage": {  //对表格国际化
                "sLengthMenu": "每页显示 _MENU_条",
                "sZeroRecords": "没有找到符合条件的数据",
                //  "sProcessing": "&lt;img src=’./loading.gif’ /&gt;",
                "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
                "sInfoEmpty": "当前第 0 - 0 条　共计 0 条",
                "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
                "sSearch": "搜索：",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"

                }
            },
            //"processing": true, //打开数据加载时的等待效果
            "serverSide": true,//打开后台分页
           /* "order": [[ 3, "desc" ]],*/
            "ajax": {
                "url": "/sysrole/queryTableData",
                "dataSrc": "aaData",
                "data": function ( d ) {
                    var name = $('#gadname').val();
                    var status = $('#status').val();
                    //添加额外的参数传给服务器
                    d.name = name;
                    d.status = status;
                }
            },
            "columns": [
                { "data": "name" ,"defaultContent": "--","bSortable": false},
                { "data": "departmentName","defaultContent": "--","bSortable": false},
                { "data": "roleTypeName" ,"defaultContent": "--","bSortable": false},
                { "data": "status" ,"defaultContent": "--","bSortable": false},
                { "data": "createTime" ,"defaultContent": "--","bSortable": false},
                { "data": "updateTime" ,"defaultContent": "--","bSortable": false}

            ],

            "columnDefs" : [ {
                // 定义操作列,######以下是重点########
                "targets" : 6,//是操作按钮目标列
                "data" : null,
                "render" : function(data, type,row) {
                    var id = '"' + row.tid + '"';
                    var flag = row.status;
                    var html = "";
                    <shiro:hasPermission name="sysMag:role:list:edit">
                    html =  "<a href='javascript:void(0);' onclick='toedit("+ id + ")' class='btn-link'>编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;";
                    </shiro:hasPermission>
                    var checkId = ","+row.tid+",";
                    if(roleIds.indexOf(checkId)>-1){
                        return html;
                    }
                    if(0==flag){
                        <shiro:hasPermission name="sysMag:role:list:disable">
                        html += "<a href='javascript:void(0);'   onclick='upRoleFlag("+ id + ",1)'  class='btn-link'>禁用</a>"
                        </shiro:hasPermission>
                    }else{
                        <shiro:hasPermission name="sysMag:role:list:enable">
                        html += "<a href='javascript:void(0);'   onclick='upRoleFlag("+ id + ",0)'  class='btn-link'>启用</a>"
                        </shiro:hasPermission>
                    }
                    return html;
                }
            },{
                // 定义操作列,######以下是重点########
                "targets" : 3,//是操作按钮目标列
                "data" : null,
                "render" : function(data, type,row) {
                    var type =  row.status;
                    var html = "使用中";
                    if('1'==type){
                        html = "已禁用";
                    }
                    return html;
                }
            } ]

        } );
    } );


    function search(){
        table.ajax.reload();
    }
    function oneOnclick(obj) {
        obj = $(obj);
        if(obj.attr("checked")){
            obj.parents('label').next('ul').find('input[type=checkbox]').attr("checked",true);
            /*obj.parents('label').parents('div').parents('div').children('.checkJstShow3').find('input[type=checkbox]').attr("checked",true);
            obj.parents('label').parents('div').parents('div').children('.checkJstShow4').find('input[type=checkbox]').attr("checked",true);*/
        }else{
            obj.parents('label').next('ul').find('input[type=checkbox]').attr("checked",false);
            /*obj.parents('label').parents('div').parents('div').children('.checkJstShow3').find('input[type=checkbox]').attr("checked",false);
            obj.parents('label').parents('div').parents('div').children('.checkJstShow4').find('input[type=checkbox]').attr("checked",false);*/
        }
    }
    function oneTwoclick(obj) {
        obj = $(obj);
        if(obj.attr("checked")){
            obj.parents('label').parents('div').parents('div').children('.checkJstShow3').find('input[type=checkbox]').attr("checked",true);
            obj.parents('label').parents('div').parents('div').children('.checkJstShow4').find('input[type=checkbox]').attr("checked",true);
        }else{
            obj.parents('label').parents('div').parents('div').children('.checkJstShow3').find('input[type=checkbox]').attr("checked",false);
            obj.parents('label').parents('div').parents('div').children('.checkJstShow4').find('input[type=checkbox]').attr("checked",false);
        }
    }
    function oneThreeclick(obj) {
        obj = $(obj);
        if(obj.attr("checked")){
            obj.parents('label').parents('div').parents('div').children('.checkJstShow4').find('input[type=checkbox]').attr("checked",true);
        }else{
            obj.parents('label').parents('div').parents('div').children('.checkJstShow4').find('input[type=checkbox]').attr("checked",false);
        }
    }


    /*function oneOnclick(obj) {
        obj = $(obj);
        if(obj.attr("checked")){
            obj.parents('td:first').next().find('input[type=checkbox]').attr("checked",true);
        }else{
            obj.parents('td:first').next().find('input[type=checkbox]').attr("checked",false);
        }
    }

    function secondOnclick(obj) {
        obj = $(obj);
        if(obj.attr("checked")){
            obj.parents('label:first').find('input[type=checkbox]').attr("checked",true);
            obj.parents('td:first').prev().find('input[type=checkbox]').attr("checked",true);
        }else{
            obj.parents('td:first').find('input[type=checkbox]').attr("checked",false);
        }
    }*/

    function thirdOnclick(obj) {
        obj = $(obj);
        if(obj.attr("checked")){
            obj.parents('div:first').find('input[type=checkbox]').eq(0).attr("checked",true);
            obj.parents('td:first').prev().find('input[type=checkbox]').attr("checked",true);
        }
    }
    function only() {
        var name = $("#add_Name").val();
        jQuery.ajax({
            type:"GET",
            url:"<%=path%>/sysrole/only/"+name,
            dataType:"json",
            success : function(data) {
                if (data.success == false) {
                    $("#add_Name").focus();
                    $("#add_Name").attr("value","");
                    $("#spanMessage").css("color","red");
                    $("#spanMessage").html("(抱歉,此处角色已经添加)");
                    return false;
                }else{
                    $("#spanMessage").html("");
                    return true;
                }
            }
        });

    }

    function check(ele) {
        var result = false;
        $(ele).find('input[name="idList"]').each(function () {
            if($(this).get(0).checked){
                result = true;
            }
        });
        if(!result){
            $("#showSubInfo").html(" 角色授权至少选择一个");
            $("#subButtonYes").attr("onclick","closeModal();");
            $("#modal-subInfo").modal('show');
        }
        return result;
    }
    function closeModal(){
        $("#modal-subInfo").modal('hide');
    }


    function patternHtml(inputId,spanId) {
        var inputValue = $("#"+inputId+"").val();
        var result=inputValue.match("<[^>]*>");
        if (result!=null) {
            $("#"+spanId+"").focus();
            $("#"+spanId+"").attr("value","");
            $("#"+spanId+"").css("color","red");
            $("#"+spanId+"").html("(不可以含有HTML标签)");
            return false;

        }else{
            $("#"+spanId+"").html("");
            return true;
        }
    }

    function getDataType(){
        var roleDataId = "XXXX";
        var tid = $("#departmentId").val();
        var _data = {};
        _data.tid = tid;
        $.ajax({
            type:"POST",
            dataType:"json",
            async:true,
            url:"${ctx}/sysrole/getDataType",
            data:_data,
            success:function(data){
                $("#roleTypeId").html("");
                $("#roleTypeId").append("<option value=''>请选择</option>");
                if(data.type=="S"){
                    for(var i=0;i<data.dataList.length;i++){
                        if(roleDataId == data.dataList[i].tid){
                            var options = '<option selected="selected" value='+data.dataList[i].tid+' level='+data.dataList[i].level+'>'+data.dataList[i].officeName+'</option>';
                        }else{
                            var options = '<option value='+data.dataList[i].tid+' level='+data.dataList[i].level+'>'+data.dataList[i].officeName+'</option>';
                        }
                        $("#roleTypeId").append(options);
                    }
                }
            }
        });
    }
    function getEDataType(typeId){
        var roleDataId = typeId;
        var tid = $("#departmentEId").val();
        var _data = {};
        _data.tid = tid;
        $.ajax({
            type:"POST",
            dataType:"json",
            async:true,
            url:"${ctx}/sysrole/getDataType",
            data:_data,
            success:function(data){
                $("#roleETypeId").html("");
                $("#roleETypeId").append("<option value=''>请选择</option>");
                if(data.type=="S"){
                    for(var i=0;i<data.dataList.length;i++){
                        if(roleDataId == data.dataList[i].tid){
                            var options = '<option selected="selected" value='+data.dataList[i].tid+' level='+data.dataList[i].level+'>'+data.dataList[i].officeName+'</option>';
                        }else{
                            var options = '<option value='+data.dataList[i].tid+' level='+data.dataList[i].level+'>'+data.dataList[i].officeName+'</option>';
                        }
                        $("#roleETypeId").append(options);
                    }
                }
            }
        });
    }

    function setLevel() {
        var options=$("#roleTypeId option:selected");
        var rLevel = options.attr("level");
        $("#roleLevel").val(rLevel);
    }
    function setELevel() {
        var options=$("#roleETypeId option:selected");
        var rLevel = options.attr("level");
        $("#roleELevel").val(rLevel);
    }
    function cleacleanTabs(){
        var i = 0;
        $("#insurerTabs").find("li").each(function(){
            if(i>1){
                $(this).remove();
            }
            i++;
        });
        $("#tid").val("");
        $("#name").val("");
        $("#departmentEId").val("");
        $("#roleELevel").val("");
    }
    function goBack(){
        $("#showSubInfo").html(" 当前填写内容未提交，确认取消？");
        $("#subButtonYes").attr("onclick","toRefresh();");
        $("#modal-subInfo").modal('show');
    }
    function toRefresh(){
        window.location.href="<%=path%>/sysrole/tolist";
    }

    function submitAddInfo(){
        $("#modal-subInfo").modal('hide');
        $("#subButtonYes").removeAttr("onclick");
        var name = $("#add_Name").val();
        jQuery.ajax({
            type:"GET",
            url:"<%=path%>/sysrole/only/"+name,
            dataType:"json",
            success : function(data) {
                if (data.success == false) {
                    $("#add_Name").focus();
//                    $("#add_Name").attr("value","");
                    $("#spanMessage").css("color","red");
                    $("#spanMessage").html("(抱歉,此角色已经添加)");
                }else{
                    $("#spanMessage").html("");
                    $("#addRoleForm").ajaxSubmit({
                        type: "POST",
                        url:"<%=path%>/sysrole/add",
                        success: function(data){
                            if(data.type =="S"){
                                $("#showSubInfo").html(" 提交成功!");
                                $("#subButtonYes").attr("onclick","toRefresh();");
                                $("#modal-subInfo").modal('show');
                            }else{
                                $("#showSubInfo").html(" 提交失败");
                                $("#modal-subInfo").modal('show');
                            }
                        }
                    });
                }
            }
        });
    }
    function submitEditInfo(){
        $("#modal-subInfo").modal('hide');
        $("#subButtonYes").removeAttr("onclick");
        $("#editRoleForm").ajaxSubmit({
            type: "POST",
            url: "<%=path%>/sysrole/add",
            success: function (data) {
                if (data.type == "S") {
                    $("#showSubInfo").html(" 提交成功!");
                    $("#subButtonYes").attr("onclick", "toRefresh();");
                    $("#modal-subInfo").modal('show');
                } else {
                    $("#showSubInfo").html(" 提交失败");
                    $("#modal-subInfo").modal('show');
                }
            }
        });
    }
</script>
</body>
</html>
